package model.admin;

import java.util.ArrayList;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
import java.sql.*;
import vo.*;
import vo.mixed.*;
import model.admin.*;
import myutil.*;


import vo.CollegeStaffVo;

public class PopulateStaffListMo {

	ArrayList<CollegeStaffVo> staff_list=new ArrayList<CollegeStaffVo>();
	ArrayList<CollegeStaffVo> staff_edit_list=new ArrayList<CollegeStaffVo>();
	public ArrayList<CollegeStaffVo> retrievestaff() {
		// TODO Auto-generated method stub
		try {
			Connect c=new Connect();
			ResultSet rs=c.getResult("select * from college_staff where status='Active'");
			while(rs.next()){
				CollegeStaffVo single_object = new CollegeStaffVo();
				single_object.setStaff_id(rs.getInt("staff_id"));
				single_object.setStaff_name(rs.getString("staff_name"));
				single_object.setDesignation(rs.getString("designation"));
				single_object.setJoining_date(rs.getString("joining_date"));
				single_object.setPhone_number(rs.getString("phone_number"));
				single_object.setAddress_line(rs.getString("address_line"));
				single_object.setCity(rs.getString("city"));
				single_object.setState(rs.getString("state"));
				single_object.setCountry(rs.getString("country"));
				single_object.setEmail_id(rs.getString("email_id"));
				single_object.setStaff_type(rs.getInt("staff_type"));
				single_object.setRole(rs.getString("role"));
				single_object.setRoll_number(rs.getString("roll_number"));
				single_object.setAcc_no(rs.getInt("acc_no"));
				single_object.setStaff_id(rs.getInt("staff_id"));
                staff_list.add(single_object);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return staff_list;
	}


	public ArrayList<CollegeStaffVo> singleStaffInfo(int staff_id) {
		// TODO Auto-generated method stub
		try {
			Connect c=new Connect();
			ResultSet rs=c.getResult("select * from college_staff where staff_id="+staff_id);
			while(rs.next()){
				CollegeStaffVo single_object = new CollegeStaffVo();
				single_object.setStaff_id(rs.getInt("staff_id"));
				single_object.setStaff_name(rs.getString("staff_name"));
				single_object.setDesignation(rs.getString("designation"));
				single_object.setJoining_date(rs.getString("joining_date"));
				single_object.setPhone_number(rs.getString("phone_number"));
				single_object.setAddress_line(rs.getString("address_line"));
				single_object.setCity(rs.getString("city"));
				single_object.setState(rs.getString("state"));
				single_object.setCountry(rs.getString("country"));
				single_object.setEmail_id(rs.getString("email_id"));
				single_object.setStaff_type(rs.getInt("staff_type"));
				single_object.setRole(rs.getString("role"));
				single_object.setRoll_number(rs.getString("roll_number"));
				single_object.setAcc_no(rs.getInt("acc_no"));
				single_object.setStaff_id(rs.getInt("staff_id"));
				staff_edit_list.add(single_object);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return staff_edit_list;
	}
	
	public void updateStaff(int staff_id,String staff_name,String designation,String joining_date,String phone_number,String address_line,
							String city,String state,String country,int staff_type,String role,String type){
		String query="update college_staff set staff_name='"+staff_name+"',designation='"+designation+"',"+
					 "joining_date='"+joining_date+"',phone_number='"+phone_number+"',address_line='"+address_line+"',"+
					 "city='"+city+"',state='"+state+"',country='"+country+"',staff_type="+staff_type+",role='"+role+"'"+
					 "where staff_id="+staff_id;
		System.out.println(query);
		Connect c= new Connect();
		try {
			c.dml(query);
			c.logger(type, "Update");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
				
	}

	public void deleteStaff(int staff_id,String type) {
		String query="";
		query="update college_staff set status='Inactive' where staff_id="+staff_id;
		Connect c=new Connect();
		try {
			c.dml(query);
			c.logger(type, "Update");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void addstaff(int staff_id,String staff_name,String designation,String joining_date,String phone_number,String address_line,
			String city,String state,String country,String email_id,int staff_type,String role,String roll_number,int acc_no,String type){
		
		String query;
		query="insert into college_staff(staff_name,designation,joining_date,phone_number,address_line,city,state,country,email_id,staff_type,role,roll_number,acc_no,status) values('"+staff_name+"','"+designation+"','"+joining_date+"','"+phone_number+"','"+address_line+"','"+city+"','"+state+"','"+country+"','"+email_id+"',"+staff_type+" ,'"+role+"','"+roll_number+"',"+acc_no+",'Active')";
		System.out.println(query);
		Connect c = new Connect();
		try {
			c.dml(query);
			c.logger(type, "Insert");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
